package com.dreamcode.caloriestracker.activities;

import java.util.LinkedList;
import java.util.List;

import com.dreamcode.caloriestracker.collectors.ProfileDAO;
import com.dreamcode.caloriestracker.collectors.ProfileDAOimpl;
import com.dreamcode.caloriestracker.modelclass.ProfileDetails;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class CaloriesTracker extends Activity {
    /** Called when the activity is first created. */
	
	private LinearLayout profileInfo = null;
	private LinearLayout calorieCalc = null;
	private LinearLayout calorieCompare = null;
	private LinearLayout realTimeTracker = null;	
	private ProfileDAO profileDAO = null;
	private ProfileDetails profileDetails = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        initView();
    }
    
    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
    	MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.firstmenu, menu);
    	//menu.add(0, 0, 0, "About");
    	//menu.add(0, 1, 0, "Settings");
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch(item.getItemId()){
			case R.id.about_menu:
				AlertDialog groupDialog = new AlertDialog.Builder(CaloriesTracker.this).setTitle("About")
				.setMessage("Calories Tracker Lite V1.0\n\nCopyright (C) DreamCode 2009-2010\n\nHome:\nhttp://genitravel.blogspot.com/\n\nEmail:\nzarko.popovski@gmail.com")
				.setPositiveButton("Homepage", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {						  
						Intent intent = new Intent(
								Intent.ACTION_VIEW,
								Uri.parse("http://genitravel.blogspot.com/"));

						startActivity(intent);					
					}
				})
				.setNegativeButton("OK", null)
				.show();		
				return true;
			/*case 1:
				return true;*/
			default: break;
		}
		
		
		return false;
	}

	public void initView(){
    	setContentView(R.layout.main);
    	profileDAO = ProfileDAOimpl.getInstance();    	 
    	profileInfo = (LinearLayout) findViewById(R.id.profile_info);
    	profileInfo.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent i = new Intent(CaloriesTracker.this,ProfileInfoActivity.class);				
				startActivity(i);				
				
			}
		});

    	calorieCalc = (LinearLayout) findViewById(R.id.calories_calc);
    	calorieCalc.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				profileDetails = profileDAO.getProfileDetails(CaloriesTracker.this, 0);
				if(profileDetails!=null){
					Intent i = new Intent(CaloriesTracker.this,CaloriesCalculatorActivity.class);				
					startActivity(i);
				}else
					Toast.makeText(CaloriesTracker.this, "Please create profile first", Toast.LENGTH_SHORT).show();
				
			}
		});    	
    	calorieCompare = (LinearLayout) findViewById(R.id.sports_comp);
    	calorieCompare.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				profileDetails = profileDAO.getProfileDetails(CaloriesTracker.this, 0);
				if(profileDetails!=null){
					Intent i = new Intent(CaloriesTracker.this,CaloriesCompareActivity.class);				
					startActivity(i);
				}else
					Toast.makeText(CaloriesTracker.this, "Please create profile first", Toast.LENGTH_SHORT).show();
				
			}
		});

    	realTimeTracker = (LinearLayout) findViewById(R.id.realtime_track);
    	realTimeTracker.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				profileDetails = profileDAO.getProfileDetails(CaloriesTracker.this, 0);
				if(profileDetails!=null){
					Intent i = new Intent(CaloriesTracker.this,RealTimeWorkoutActivity.class);				
					startActivity(i);
				}else
					Toast.makeText(CaloriesTracker.this, "Please create profile first", Toast.LENGTH_SHORT).show();
			}
		});

    	     	
    }  
    
}